package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.Sms_Seckill_Promotion_Mapper;
import com.shop.service.Sms_Seckill_Promotion_Service;
import com.shop.pojo.sms.Sms_Seckill_promotion;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Sms_Seckill_Promotion_ServiceImpl implements Sms_Seckill_Promotion_Service

{

    @Autowired
    private Sms_Seckill_Promotion_Mapper sms_seckill_promotion_mapper;


    @Override
    public LayuiUtils<Sms_Seckill_promotion> find_admin_seckill_promotion_All(Page<Sms_Seckill_promotion> pages, Sms_Seckill_promotion ssp) {
        LayuiUtils<Sms_Seckill_promotion> layuis = new LayuiUtils<>();
        QueryWrapper<Sms_Seckill_promotion> queryWrapper = new QueryWrapper();

        if(ssp.getTitle() != null){
            queryWrapper.like("title",ssp.getTitle());
        }


        Page<Sms_Seckill_promotion> sms_seckill_promotionPage = sms_seckill_promotion_mapper.selectPage(pages, queryWrapper);

        layuis.setCount(sms_seckill_promotionPage.getTotal());
        layuis.setData(sms_seckill_promotionPage.getRecords());
        return layuis;
    }

    @Override
    public R insert_admin_seckill_promotion_All(Sms_Seckill_promotion ssp) {
        int insert = sms_seckill_promotion_mapper.insert(ssp);
        if(insert > 0){
            return R.success();
        }
        return R.error(500,"添加失败");
    }

    @Override
    public R del_admin_seckill_promotion_All(List<Integer> id) {
        int i = sms_seckill_promotion_mapper.deleteBatchIds(id);
        if(i > 0){
            return R.success();
        }
        return R.error(500,"删除失败");
    }

    @Override
    public R up_admin_seckill_promotion_All(Sms_Seckill_promotion ssp) {
        int i = sms_seckill_promotion_mapper.updateById(ssp);
        if(i > 0){
            return R.success();
        }
        return R.error(500,"修改失败");
    }
}
